
# 10  给定一段英文文本，统计每个单词出现的次数；打印输出，按照词频从高到低输出：
#    提示：可以用字典来统计：key 是单词，value 是单词出现次数；
#     先创建一个字典，然后遍历刚刚取出的单词列表，接着做一个判断： 如果字典中 key 已经出现了这个单词，那么它对应的 value ，也就是出现次数就 +1； 如果这个单词没出现过，就直接 插入这个单词及 value 为 1 到 字典中；


def word_frequency(text):
    words = text.split()
    frequency = {}

    for word in words:
        word = word.lower()  # Convert to lowercase to ensure case-insensitivity
        if word in frequency:
            frequency[word] += 1
        else:
            frequency[word] = 1

    sorted_frequency = sorted(frequency.items(), key=lambda x: x[1], reverse=True)
    for word, count in sorted_frequency:
        print(f"{word}: {count}")

text = "You cannot improve your past,but you can improve your future.Once time is wasted,life is wasted."
word_frequency(text)